<template>
  <!-- 115新增录入画面对话框-->
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <el-form ref="editForm" :model="form" :rules="rules" label-width="110px">
      <!--交易础信息-->
      <el-card class="form-card txnInfo-card">
        <div slot="header" class="label-header-msg">
          <span>交易基础信息</span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="业务类型" prop="bizTypeCode">
              <el-select v-model="form.bizTypeCode" placeholder="业务类型" @change="bizTypeCodeChange">
                <el-option
                  v-for="dict in dictMap.BIZ_TYPE_115"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务种类" prop="bizCtgyCode">
              <el-select v-model="form.bizCtgyCode" placeholder="业务种类" @change="bizCtgyCodeChange">
                <el-option
                  v-for="dict in busTypeList"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务优先级" prop="bizPriority">
              <el-select v-model="form.bizPriority" placeholder="业务优先级">
                <el-option
                  v-for="dict in dictMap.PRIORITY3CODE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="交易渠道" prop="source">
              <el-select v-model="form.source" placeholder="柜面交易" disabled>
                <el-option
                  v-for="dict in dictMap.TXN_SOURCE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="记账标志" prop="cbflag">
              <el-select v-model="form.cbflag" placeholder="记账标志">
                <el-option
                  v-for="dict in dictMap.CBFLAG"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="账户类型" prop="custFlag1">
              <el-select v-model="form.custFlag1" placeholder="账户类型">
                <el-option
                  v-for="dict in dictMap.CUST_FLAG1"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="交易币种" prop="curcd">
              <el-input v-model="form.curcd" placeholder="人民币-CNY" :disabled="true" style="width: 195px"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="交易金额" prop="amount">
              <ht-amount-input
                v-model="form.amount"
                placeholder="交易金额"
                style="width: 195px"
                @keyup.enter.native="checkAmountLimit()"
              ></ht-amount-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="大写金额" prop="bAmount">
              <ht-amount-upper :inputValue="form.amount" placeholder="交易金额" style="width: 195px"></ht-amount-upper>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <!--付款人信息-->
      <el-card class="form-card payerInfo-card">
        <div slot="header" class="label-header-msg">
          <span>付款人信息</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="付款人账号" prop="payerActno">
              <acct-no-input
                v-model="form.payerActno"
                placeholder="付款人账号"
                @keyup.enter.native="getActNoInfo('payerActNo')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-row>
              <el-button type="primary" icon="el-icon-search" plain @click="openPayerDialog('payerActno')">
                账号查找
              </el-button>
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="付款人名称" prop="payerName">
            <el-input v-model="form.payerName" placeholder="付款人名称"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="付款人地址" prop="payerAddr">
            <el-input v-model="form.payerAddr" placeholder="付款人地址"/>
          </el-form-item>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payer">
              <el-form-item label="付款行行号" prop="payerBrno">
                <BrnoInput
                  v-model="form.payerBrno"
                  placeholder="付款行行号"
                  :disabled="true"
                  @keyup.enter.native="getBankInf('payerBrno', form.payerBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="2">
            <el-button type="primary" icon="el-icon-search" disabled plain @click="openBankBranchDialog('payerBrno')">
              行号查找
            </el-button>
          </el-col>
          <el-col :span="14">
            <el-form-item label="付款行行名" prop="payerBrname" label-width="130px">
              <el-input v-model="form.payerBrname" disabled placeholder="付款行行名"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payer">
              <el-form-item label="付款人开户行号" prop="payerAccBrno">
                <BrnoInput
                  v-model="form.payerAccBrno"
                  placeholder="付款人开户行行号"
                  @keyup.enter.native="getBankInf('payerAccBrno', form.payerAccBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="2">
            <div class="grid-payer">
              <el-button type="primary" icon="el-icon-search" plain @click="openBankBranchDialog('payerAccBrno')">
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="14">
            <el-form-item label="付款人开户行行名" prop="payerAccBrname" label-width="130px">
              <el-input v-model="form.payerAccBrname" placeholder="付款人开户行行名"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <!--收款人信息-->
      <el-card class="form-card payeeInfo-card">
        <div slot="header" class="label-header-msg">
          <span>收款人信息</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="12">
            <div class="grid-payee">
              <el-form-item label="收款人账号" prop="payeeActno">
                <acct-no-input
                  v-model="form.payeeActno"
                  placeholder="收款人账号"
                  @keyup.enter.native="getActNoInfo('payeeActNo')"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="grid-payee">
              <el-button type="primary" icon="el-icon-search" plain @click="openPayeeDialog('payeeActno')">
                账号查找
              </el-button>
            </div>
          </el-col>
        </el-row>
        <el-form-item label="收款人名称" prop="payeeName">
          <el-input v-model="form.payeeName" placeholder="收款人名称"/>
        </el-form-item>
        <el-form-item label="收款人地址" prop="payeeAddr">
          <el-input v-model="form.payeeAddr" placeholder="收款人地址"/>
        </el-form-item>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payee">
              <el-form-item label="收款行行号" prop="payeeBrno">
                <BrnoInput
                  v-model="form.payeeBrno"
                  placeholder="收款行行号"
                  :readonly="form.bizTypeCode === 'A202'"
                  @keyup.enter.native="getBankInf('payeeBrno', form.payeeBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="3">
            <div class="grid-payee">
              <el-button
                type="primary"
                icon="el-icon-search"
                plain
                :disabled="form.bizTypeCode === 'A202'"
                @click="openBankBranchDialog('payeeBrno')"
              >
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="13">
            <el-form-item label="收款行行名" prop="payeeBrname" label-width="130px">
              <el-input v-model="form.payeeBrname" placeholder="收款行行名"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payee">
              <el-form-item label="收款人开户行号" prop="payeeAccBrno">
                <BrnoInput
                  v-model="form.payeeAccBrno"
                  placeholder="收款人开户行行号"
                  @keyup.enter.native="getBankInf('payeeAccBrno', form.payeeAccBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="3">
            <div class="grid-payee">
              <el-button type="primary" icon="el-icon-search" plain @click="openBankBranchDialog('payeeAccBrno')">
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="13">
            <el-form-item label="收款人开户行行名" prop="payeeAccBrname" label-width="130px">
              <el-input v-model="form.payeeAccBrname" placeholder="收款人开户行行名"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <!--其他信息-->
      <el-card class="form-card payOtherInfo-card">
        <div slot="header" class="label-header-msg">
          <span>其他交易信息</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-otherInfo">
              <el-form-item label="中介机构1" prop="agency1">
                <BrnoInput
                  v-model="form.agency1"
                  placeholder="中介机构1"
                  @keyup.enter.native="getBankInf('agency1', form.agency1)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="2">
            <div class="grid-otherInfo">
              <el-button type="primary" icon="el-icon-search" plain @click="openBankBranchDialog('agency1')">
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="14">
            <el-form-item label="中介机构1名称" prop="agency1name" label-width="130px">
              <el-input v-model="form.agency1name" placeholder="中介机构1名称"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-otherInfo">
              <el-form-item label="中介机构2" prop="agency2">
                <BrnoInput
                  v-model="form.agency2"
                  placeholder="中介机构2"
                  @keyup.enter.native="getBankInf('agency2', form.agency2)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="2">
            <div class="grid-otherInfo">
              <el-button type="primary" icon="el-icon-search" plain @click="openBankBranchDialog('agency2')">
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="14">
            <el-form-item label="中介机构2名称" prop="agency2name" label-width="130px">
              <el-input v-model="form.agency2name" placeholder="中介机构2名称"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="grid-otherInfo">
              <el-form-item label="备注" prop="remarks">
                <el-input type="textarea" v-model="form.remarks" placeholder="备注" maxlength="135" show-word-limit/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-card>
      <!--todo 有几个附加域处理需要调整 -->
      <el-card class="form-card payAddInfo-card" v-if="form.bizTypeCode === 'A113'">
        <div slot="header" class="label-header-msg">
          <span>跨境支付附加域信息</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="关联业务委托日期" prop="cbbizAssocBizDate" label-width="120px">
              <el-date-picker
                style="width: 185px"
                v-model="form.cbbizAssocBizDate"
                type="date"
                value-format="yyyyMMdd"
                placeholder="选择日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <!--          <el-col :span="10">
                      &lt;!&ndash;当业务类型为“跨境支付”时：“端到端标识号”填写内容为“关联业务参考号&ndash;&gt;
                      <el-form-item label="关联业务参考号" prop="e2eId" label-width="110px">
                        <el-input v-model="form.e2eId" placeholder="关联业务参考号" />
                      </el-form-item>
                    </el-col>-->
        </el-row>

        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payAddInfo">
              <el-form-item label="费用编码" prop="cbbizFeeCode" label-width="120px">
                <acct-no-input v-model="form.cbbizFeeCode" placeholder="费用编码"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="grid-payAddInfo">
              <el-form-item label="发报行的收费" prop="cbbizSndbnkFee" label-width="110px">
                <ht-amount-input v-model="form.cbbizSndbnkFee" placeholder="发报行的收费"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="grid-payAddInfo">
              <el-form-item label="收报行的收费" prop="cbbizRcvbnkFee" label-width="110px">
                <ht-amount-input v-model="form.cbbizRcvbnkFee" placeholder="收报行的收费"/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="跨境业务附言" prop="cbbizRemark" label-width="120px">
              <el-input
                type="textarea"
                v-model="form.cbbizRemark"
                placeholder="跨境业务附言"
                maxlength="135"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <el-card class="form-card payAddInfo-card" v-if="form.bizTypeCode === 'A105'">
        <div slot="header" class="label-header-msg">
          <span>退汇附加域信息</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="原报文标识号" prop="oriPkgId" label-width="110px">
              <el-input v-model="form.oriPkgId" placeholder="原报文标识号"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="原发起参与机构" prop="oriSender" label-width="110px">
              <el-input v-model="form.oriSender" placeholder="原发起参与机构"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="原报文类型代码" prop="oriMsgType" label-width="110px">
              <el-select v-model="form.oriMsgType" placeholder="原报文类型代码">
                <el-option
                  v-for="dict in dictMap.BIZ_TYPE_115"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
              <!-- <el-input v-model="form.oriMsgType" placeholder="原报文类型代码" /> -->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="grid-otherInfo">
              <el-form-item label="退汇原因" prop="returnReason">
                <el-input type="textarea" v-model="form.returnReason" placeholder="退汇原因" maxlength="135"
                          show-word-limit/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-card>

      <el-card class="form-card payAddInfo-card" v-if="form.bizTypeCode === 'A200'">
        <div slot="header" class="label-header-msg">
          <span>行间资金汇划</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="10">
            <el-form-item label="拆借利率(单位:万分之一)" prop="lendIntRate" label-width="110px">
              <acct-no-input v-model="form.lendIntRate" placeholder="拆借利率"/>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="拆借期限" prop="lendDline" label-width="110px">
              <acct-no-input v-model="form.lendDline" placeholder="拆借期限"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
      <el-button v-if="ifShowDelBtn" type="danger" @click="delTran">删 除</el-button>
    </div>
    <bank-branch-dialog ref="bankBranchDialog" @confirm="confirmBankBranch"></bank-branch-dialog>
    <payee-dialog ref="payeeDialog" @confirm="confirmPayee"></payee-dialog>
    <payer-dialog ref="payerDialog" @confirm="confirmPayer"></payer-dialog>
  </el-dialog>
</template>
<script>
import {addHvps115, updataHvps115, updTxn} from '@/api/cnaps/baseBiz/send/hvps/hvps.js'
import {delTxn, detail} from "@/api/cnaps/baseBiz/send/sendCommon.js";
import {getOtherCustByActno, getCustByActno} from "@/api/cnaps/common/custInfo";
import {getBankInfByBankCode} from "@/api/cnaps/common/bankInfo";
import {isLessThenHvpsMinLimitNew} from "@/api/cnaps/common/cp2SysParam";
import BankBranchDialog from "@/views/components/BankBranchDialog";
import PayeeDialog from "@/views/components/PayeeDialog";
import PayerDialog from "@/views/components/PayerDialog";
import HtAmountInput from "@/views/components/HtAmountInput";
import HtAmountUpper from "@/views/components/HtAmountUpper";
import AcctNoInput from "@/views/components/AcctNoInput";
import {mapGetters} from "vuex";
import BrnoInput from "@/views/components/BrnoInput/index.vue";

export default {
  name: "EditInfo",
  components: {
    PayeeDialog,
    PayerDialog,
    BankBranchDialog,
    HtAmountInput,
    HtAmountUpper,
    AcctNoInput,
    BrnoInput
  },
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      busTypeList: [],
      id: "",
      title: "",
      pkgNo: "",
      // 是否显示弹出层
      openState: false,
      ifShowDelBtn: false,
      amount: "0.00",
      // 字段可编辑控制

      // 表单参数
      form: {
        amount: "0.00",
      },
      // 表单校验
      rules: {
        bizTypeCode: [{required: true, message: "请输入业务类型", trigger: "blur"}],
        bizCtgyCode: [{required: true, message: "请输入业务种类", trigger: "blur"}],
        bizPriority: [{required: true, message: "请输入业务优先级", trigger: "blur"}],
        payerBrno: [{required: true, max: 14, message: "请输入付款行号", trigger: "blur"}],
        payerBrname: [{max: 60, message: "请输入付款行名", trigger: "blur"}],
        payerAccBrno: [{message: "请输入付款开户行号", trigger: ['blur', 'change']},
          {max: 35, message: "付款开户行号最长35位", trigger: ['blur', 'change']}],
        payerAccBrname: [{max: 140, message: "付款人开户行行名最长140位", trigger: ['blur', 'change']}],
        payerActno: [{required: true, message: "请输入付款人账号", trigger: ['blur', 'change']},
          {max: 32, message: "付款人账号最长32位", trigger: ['blur', 'change']}],
        payerName: [{required: true, message: "请输入付款人名称", trigger: ['blur', 'change']},
          {max: 60, message: "付款人名称最长60位", trigger: ['blur', 'change']}],
        payerAddr: [{max: 70, message: "付款人地址最长70位", trigger: ['blur', 'change']}],
        payeeActno: [{required: true, message: "请输入收款人账号", trigger: ['blur', 'change']},
          {max: 32, message: "收款人账号最长32位", trigger: ['blur', 'change']}],
        payeeName: [{required: true, message: "请输入收款人名称", trigger: ['blur', 'change']},
          {max: 60, message: "收款人名称最长60位", trigger: ['blur', 'change']}],
        payeeAddr: [{max: 70, message: "收款人地址最长70位", trigger: ['blur', 'change']}],
        payeeBrno: [{required: true, message: "请输入收款行行号", trigger: ['blur', 'change']},
          {max: 14, message: "收款行行号最长14位", trigger: ['blur', 'change']}],
        payeeBrname: [{required: true, message: "请输入收款行行名", trigger: ['blur', 'change']},
          {max: 60, message: "收款行行名最长60位", trigger: ['blur', 'change']}],
        payeeAccBrno: [{required: true, message: "请输入收款人开户行号", trigger: ['blur', 'change']},
          {max: 35, message: "收款人开户行号最长35位", trigger: ['blur', 'change']}],
        payeeAccBrname: [{max: 140, message: "收款人开户行行名最长140位", trigger: ['blur', 'change']}],
        agency1: [{required: false, message: "请输入中介机构1", trigger: "blur"},
          {max: 35, message: "中介机构1最长35位", trigger: "blur"}],
        agency1name: [{max: 140, message: "中介机构1名称最长140位", trigger: "blur"}],
        agency2: [{required: false, message: "请输入中介机构2", trigger: "blur"},
          {max: 35, message: "中介机构2最长35位", trigger: "blur"}],
        agency2name: [{max: 140, message: "中介机构2名称最长140位", trigger: "blur"}],
        amount: [{required: true, message: "请输入交易金额", trigger: "blur"}],
        remarks: [{required: false, message: "请输入备注", trigger: "blur"}],
        remarksAll: [{required: false, max: 140, trigger: "blur"}],
        cbbizFeeCode: [{max: 3, message: "费用编码最长为3位", trigger: "blur"}],
        oriPkgId: [{max: 35, message: "原报文标识号最长为35位", trigger: "blur"}],
        oriSender: [{max: 14, message : "原发起参与机构最长为14位", trigger: "blur"}],
        returnReason: [{max: 135,message: "退汇原因最长135位", trigger: "blur"}],
        lendIntRate: [{required: false, message: "请输入拆借利率", trigger: "blur"},
          {max: 7, message: "拆借利率最长7位", trigger: "blur"}],
        lendDline: [{required: false, message: "请输入拆借期限", trigger: "blur"},
          {max: 5, message: "拆借期限最长5位", trigger: "blur"}],
      },
    };
  },
  mounted() {
  },
  computed: {
    ...mapGetters(["globalBusData"]),
  },
  methods: {
    // 表单重置
    reset() {
      this.resetForm("editForm");
      this.$set(this, "form", {});
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.reset();
          done();
        })
        .catch((_) => {
        });
    },

    bizTypeCodeChange(code) {
      //联动修改bizCtgyCode
      let dictKeyPre = `BIZ_CTGY_HVPS_${code}`;
      this.getDicts(dictKeyPre).then((response) => {
        this.busTypeList = response.result;
        this.$set(this.form, "bizCtgyCode", this.busTypeList[0].value);
      });
      //画面输入要素修改------------------
      if (code == "A112" || code == "A115" || code == "A116" || code == "A117"
        || code == "A106" || code == "A200") {
        if (code !== "A106") {
          // 收款人账号 名称
          this.$set(this.rules.payeeActno[0], "required", false);
          this.$set(this.rules.payeeName[0], "required", false);
        }
        // 收款人开户行号
        this.$set(this.rules.payeeAccBrno[0], "required", false);
        if (code !== "A115" && code !== "A116" && code !== "A106" ) {
          // 付款人账号
          this.$set(this.rules.payerActno[0], "required", false);
        }
        // 付款人名称 付款开户行号
        this.$set(this.rules.payerName[0], "required", false);
        this.$set(this.rules.payerAccBrno[0], "required", false);
      } else {
        this.$set(this.rules.payeeActno[0], "required", true);
        this.$set(this.rules.payeeName[0], "required", true);
        this.$set(this.rules.payeeAccBrno[0], "required", true);
        this.$set(this.rules.payerActno[0], "required", true);
        this.$set(this.rules.payerName[0], "required", true);
        this.$set(this.rules.payerAccBrno[0], "required", true);
      }
      // bizTypeCodeChange方法中if的先后顺序不能改变
      if (code === "A106") {
        // 收款人账号 名称
        this.$set(this.rules.payeeActno[0], "required", true);
        this.$set(this.rules.payeeName[0], "required", true);
      }
      if (code === "A115" || code === "A116" || code === "A106" ) {
        // 付款人账号
        this.$set(this.rules.payerActno[0], "required", true);
      }
      if (code == "A200") {
        this.$set(this.rules.remarksAll[0], "required", false);
      }
      if (code == "A102") {
        this.$set(this.rules.remarksAll[0], "required", true);
      }
    },
    bizCtgyCodeChange() {
      //业务种类变化，城商行商业汇票特殊处理
      //城市商业银行汇票资金移存”时，“付款人开户行行号、付款人账号、付款人名称”必填，
      //“收款人开户行行号、收款人账号、收款人名称”可选填
      //城市商业银行汇票资金清算、城市商业银行汇票资金多余划回、城市商业银行汇票资金未用退回”时，
      //“收款人开户行行号、收款人账号、收款人名称”必填，
      //“付款人开户行行号、付款人账号、付款人名称”可选填；
      if (this.form.bizTypeCode == "A200") {
        switch (this.form.bizCtgyCode) {
          case "02118": {
            this.$set(this.rules.lendIntRate[0], "required", true);
            this.$set(this.rules.lendDline[0], "required", true);
            break;
          }
          case "02119": {
            this.$set(this.rules.lendIntRate[0], "required", true);
            this.$set(this.rules.lendDline[0], "required", true);
            break;
          }
          case "02120": {
            this.$set(this.rules.lendIntRate[0], "required", true);
            this.$set(this.rules.lendDline[0], "required", true);
            break;
          }
          case "02121": {
            this.$set(this.rules.lendIntRate[0], "required", true);
            this.$set(this.rules.lendDline[0], "required", true);
            break;
          }
          default: {
            this.$set(this.rules.lendIntRate[0], "required", false);
            this.$set(this.rules.lendDline[0], "required", false);
            break;
          }
        }
      }
    },
    // 回车查证账号信息
    getActNoInfo(actNoType) {
      this.form.userInfo = {brno: "676"};
      if (actNoType === "payeeActNo") {
        var actNo = this.form.payeeActno;
        getOtherCustByActno(actNo).then((response) => {
          if (response.code == "S" && response.result !== null) {
            this.$set(this.form, "payeeActno", response.result.actNo);
            this.$set(this.form, "payeeName", response.result.name);
            this.$set(this.form, "payeeBrno", response.result.rcvBrno);
            this.$set(this.form, "payeeBrname", response.result.rcvBrname);
            this.$set(this.form, "payeeAddr", response.result.addr);
            this.$set(this.form, "payeeAccBrno", response.result.accBrno);
            this.$set(this.form, "payeeAccBrname", response.result.accBrnoName);
          } else {
            this.msgSuccess("无历史付款记录");
            this.$set(this.form, "payeeName", null);
            this.$set(this.form, "payeeBrno", null);
            this.$set(this.form, "payeeBrname", null);
            this.$set(this.form, "payeeAddr", null);
            this.$set(this.form, "payeeAccBrno", null);
            this.$set(this.form, "payeeAccBrname", null);
          }
        });
      } else {
        var actNo = this.form.payerActno;
        getCustByActno(actNo).then((response) => {
          if (response.code == "S" && response.result !== null) {
            this.$set(this.form, "payerActno", response.result.actNo);
            this.$set(this.form, "payerName", response.result.name);
            this.$set(this.form, "payerAddr", response.result.addr);
          } else {
            this.msgSuccess("查无此账号");
            this.$set(this.form, "payerName", null);
            this.$set(this.form, "payerAddr", null);
          }
        });
      }
    },
    // 检查大额交易金额上限
    checkAmountLimit() {
      isLessThenHvpsMinLimitNew(this.form.bizTypeCode, this.form.bizCtgyCode, this.form.bizPriority, this.form.amount);
    },

    openBankBranchDialog(fromFlag = "") {
      this.$refs.bankBranchDialog.show(fromFlag);
    },
    confirmBankBranch(fromFlag, row) {
      if (fromFlag == "payeeBrno") {
        this.$set(this.form, "payeeBrno", row.bankCode);
        this.$set(this.form, "payeeBrname", row.orgFullname);
      } else if (fromFlag == "payerAccBrno") {
        this.$set(this.form, "payerAccBrno", row.bankCode);
        this.$set(this.form, "payerAccBrname", row.orgFullname);
      } else if (fromFlag == "payerBrno") {
        this.$set(this.form, "payerBrno", row.bankCode);
        this.$set(this.form, "payerBrname", row.orgFullname);
      } else if (fromFlag == "payeeAccBrno") {
        this.$set(this.form, "payeeAccBrno", row.bankCode);
        this.$set(this.form, "payeeAccBrname", row.orgFullname);
      } else if (fromFlag == "agency1") {
        this.$set(this.form, "agency1", row.bankCode);
        this.$set(this.form, "agency1name", row.orgFullname);
      } else if (fromFlag == "agency2") {
        this.$set(this.form, "agency2", row.bankCode);
        this.$set(this.form, "agency2name", row.orgFullname);
      }
    },
    //回车取行号信息
    getBankInf(searchType, bankCode) {
      getBankInfByBankCode(bankCode).then((response) => {
        if (response.code == "S" && response.result !== null) {
          switch (searchType) {
            case "payerBrno":
              this.$set(this.form, "payerBrno", response.result.bankCode);
              this.$set(this.form, "payerBrname", response.result.orgFullname);
              break;
            case "payerAccBrno":
              this.$set(this.form, "payerAccBrno", response.result.bankCode);
              this.$set(this.form, "payerAccBrname", response.result.orgFullname);
              break;
            case "payeeBrno":
              this.$set(this.form, "payeeBrno", response.result.bankCode);
              this.$set(this.form, "payeeBrname", response.result.orgFullname);
              break;
            case "payeeAccBrno":
              this.$set(this.form, "payeeAccBrno", response.result.bankCode);
              this.$set(this.form, "payeeAccBrname", response.result.orgFullname);
              break;
            case "agency1":
              this.$set(this.form, "agency1", response.result.bankCode);
              this.$set(this.form, "agency1name", response.result.orgFullname);
              break;
            case "agency2":
              this.$set(this.form, "agency2", response.result.bankCode);
              this.$set(this.form, "agency2name", response.result.orgFullname);
              break;
          }
        } else {
          this.msgSuccess("查无此行号");
          switch (searchType) {
            case "payerBrno":
              this.$set(this.form, "payerBrname", null);
              break;
            case "payerAccBrno":
              this.$set(this.form, "payerAccBrname", null);
              break;
            case "payeeBrno":
              this.$set(this.form, "payeeBrname", null);
              break;
            case "payeeAccBrno":
              this.$set(this.form, "payeeAccBrname", null);
              break;
            case "agency1":
              this.$set(this.form, "agency1name", null);
              break;
            case "agency2":
              this.$set(this.form, "agency2name", null);
              break;
          }
        }
      });
    },
    openPayeeDialog(fromFlag = "") {
      this.$refs.payeeDialog.show(fromFlag);
    },
    confirmPayee(fromFlag, row) {
      if (fromFlag == "payeeActno") {
        this.$set(this.form, "payeeActno", row.actNo);
        this.$set(this.form, "payeeName", row.name);
        this.$set(this.form, "payeeBrno", row.rcvBrno);
        this.$set(this.form, "payeeBrname", row.rcvBrname);
        this.$set(this.form, "payeeAddr", row.addr);
        this.$set(this.form, "payeeAccBrno", row.accBrno);
        this.$set(this.form, "payeeAccBrname", row.accBrnoName);
      }
    },
    openPayerDialog(fromFlag = "") {
      this.$refs.payerDialog.show(fromFlag);
    },
    confirmPayer(fromFlag, row) {
      if (fromFlag == "payerActno") {
        this.$set(this.form, "payerActno", row.actNo);
        this.$set(this.form, "payerName", row.name);
        this.$set(this.form, "payerAddr", row.addr);
      }
    },
    show(id = "", pkgNo = "") {
      this.reset();
      this.pkgNo = pkgNo;
      this.id = id;
      this.title = "大额延迟结算支付申请录入";
      this.openState = true;
      this.ifShowDelBtn = false;

      // 初始化选择
      this.$set(this.form, "bizTypeCode", this.dictMap.BIZ_TYPE_115[0].value);
      this.bizTypeCodeChange(this.form.bizTypeCode);
      this.$set(this.form, "bizPriority", this.dictMap.PRIORITY3CODE[0].value);
      this.$set(this.form, "custFlag1", this.dictMap.CUST_FLAG1[0].value);
      this.$set(this.form, "cbflag", this.dictMap.CBFLAG[0].value);
      this.$set(this.form, "payerBrno", this.globalBusData.cnapsBrno); //付款行号初始化当前操作员所以机构
      this.$set(this.form, "payerBrname", this.globalBusData.cnapsBrname);
      this.$set(this.form, "payerAccBrno", this.globalBusData.cnapsBrno); //付款开户行号初始化当前操作员所以机构
      this.$set(this.form, "payerAccBrname", this.globalBusData.cnapsBrname);
      this.$set(this.form, "curcd", "CNY");
      this.$set(this.form, "source", "1")

      if (id) {
        this.title = "大额延迟结算支付申请修改";
        this.ifShowDelBtn = true;

        // 如果传了ID 这里查询一个已经存在的数据
        detail({
          coreId: this.id,
          pkgNo: this.pkgNo,
        }).then((res) => {
          this.$set(this, "form", res.result.detail90115DataModel);
        });
      }
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", false);
    },
    /** TODO提交按钮 */
    submitForm: function () {
      this.$refs["editForm"].validate((valid) => {
        if (valid) {
          //如果有ID 则是修改
          if (this.id) {
            this.form.userInfo = {brno: "676", userId: "cpg001"};
            updataHvps115(this.form).then((res) => {
              this.msgSuccess("修改成功");
              this.$emit("editComplete", true);
              this.openState = false;
            });
          } else {//新增
            //this.form.userInfo = { brno: "676", userId: "cpg001" };
            addHvps115(this.form).then((res) => {
              this.msgSuccess("新增成功");

              this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
                confirmButtonText: "确定",
                //刷新一下查询列表 TODO
                callback: (action) => {
                },
              });
              this.$emit("editComplete", true);
              this.openState = false;
            });
          }
        }
      });
    },
    /** 删除 按钮 */
    delTran: function () {
      if (this.id) {
        this.$confirm("确认删除吗？", "交易删除提示", {type: "warning"}).then((_) => {
          delTxn({id: this.id}).then((res) => {
            this.msgSuccess("删除成功");

            this.$emit("editComplete", true);
            this.openState = false;
          });
        });
      }
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
